source('/home/jc148322/scripts/libraries/cool_functions.r')
library(SDMTools)

wd='/home/jc148322/frog_declines/SDM/Post_decline/';setwd(wd)
out.dir='/home/jc148322/frog_declines/SDM/Post_decline/images/';dir.create(out.dir)
var.dirs=list.files(wd)
var.dirs=grep('bioclim',var.dirs,value=T)
species=list.files(paste(wd,var.dirs[1],'/models/',sep=''))

cols=colorRampPalette(c('tan','forestgreen','olivedrab2'))(100)
	
base=read.asc.gz('/home/jc148322/frog_declines/SDM/Pre_decline/bioclim_12_15/models/acuti/output/ascii/current.76to05.asc.gz')		
for (spp in species) { cat(spp,'\n')


	png(paste(out.dir,spp,'.test.png',sep=''),width=dim(base)[1]*3, height=dim(base)[2]*3, units='px', pointsize=20, bg='white')
	par(mfrow=c(3,3),mar=c(5,5,10,5))
	for(v in var.dirs){ cat(v,'\n')
		md=paste(wd,v,'/models/',sep='')
	
		tasc=read.asc.gz(paste(md,spp,'/output/ascii/current.76to05.asc.gz', sep=''))
		occur=read.csv(paste(md, spp,'/occur.csv',sep=''),as.is=T)
		auc=read.csv(paste(md,spp,'/output/maxentResults.csv',sep=''),as.is=TRUE)
		auc=auc[1,6]
		
		image(tasc,ann=F,axes=F,col=cols,zlim=c(0,1))
		points(occur$long,occur$lat,pch=16,cex=2)
		mtext(v,line=6,side=3,cex=3)
		mtext(auc,line=1, side=3, cex=2.5)
		
	}
	dev.off()
}
